package com.ytzl.itripsearch.controller;

import com.ytzl.common.CodeResultEnums;
import com.ytzl.common.ResponseData;
import com.ytzl.common.ResponseDataUtils;
import com.ytzl.itripsearch.service.HotCityHotelService;
import com.ytzl.vo.ItripHotCityHotelVo;
import com.ytzl.vo.SearchHotCityVo;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("/api/hotellist")
public class HotelListController {

    @Autowired
    HotCityHotelService hotCityHotelService;



    @PostMapping("/searchItripHotelListByHotCity")
    public ResponseData<ItripHotCityHotelVo> queryHotCityHotelList(SearchHotCityVo searchHotCityVo) throws SolrServerException, IOException {

        //校验查询的参数

        if (searchHotCityVo!=null&&searchHotCityVo.getCityId()==null) {
            return ResponseDataUtils.buildError(CodeResultEnums.CITY_ID_IS_NULL);
        }

        //获取数据
        List<ItripHotCityHotelVo> itripHotCityHotelVo = hotCityHotelService.queryHotelCityList(searchHotCityVo.getCityId(), searchHotCityVo.getCount());

        return ResponseDataUtils.buildSuccess(itripHotCityHotelVo);
    }
}
